#!/usr/bin/python
# -*-coding:utf-8-*-
import os

from base.GPModelSave import load_gpmodel
from base.utils import writeToFile

from dir_info import existing_factor_record_dir


def main(factor_type, model_dir):
    model_file_list = os.listdir(model_dir)

    model_file_list = [m for m in model_file_list if factor_type in m]

    models_list = []

    for model_file in model_file_list:
        model = load_gpmodel(os.path.join(model_dir, model_file))

        model = [p.name if not isinstance(p, (str, int, float)) else p for p in model]

        models_list.append(model)

    save_path = os.path.join(existing_factor_record_dir, factor_type+'_existing.pkl')

    writeToFile(models_list, save_path)

